package com.ruoyi.web.controller.system;

import com.ruoyi.system.domain.vo.DefDrillByRoleVO;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DefDrill;
import com.ruoyi.system.service.IDefDrillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 演练管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-08
 */
@RestController
@RequestMapping("/system/drill")
public class DefDrillController extends BaseController
{
    @Autowired
    private IDefDrillService defDrillService;

    /**
     * 查询演练管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DefDrill defDrill)
    {
        startPage();
        List<DefDrill> list = defDrillService.selectDefDrillList(defDrill);
        return getDataTable(list);
    }

    /**
     * 演练角色列表
     */
    //@PreAuthorize("@ss.hasPermi('system:drill:listByRole')")
    @GetMapping("/list-by-role")
    public TableDataInfo listByRole(DefDrill defDrill)
    {
        startPage();
        List<DefDrillByRoleVO> list = defDrillService.listByRole(defDrill);
        return getDataTable(list);
    }

    /**
     * 导出演练管理列表
     */
    @Log(title = "演练管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DefDrill defDrill)
    {
        List<DefDrill> list = defDrillService.selectDefDrillList(defDrill);
        ExcelUtil<DefDrill> util = new ExcelUtil<DefDrill>(DefDrill.class);
        util.exportExcel(response, list, "演练管理数据");
    }

    /**
     * 获取演练管理详细信息
     */
    @GetMapping(value = "/{drillId}")
    public AjaxResult getInfo(@PathVariable("drillId") Integer drillId)
    {
        return success(defDrillService.selectDefDrillByDrillId(drillId));
    }

    /**
     * 新增演练管理
     */
    @Log(title = "演练管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DefDrill defDrill)
    {
        return toAjax(defDrillService.insertDefDrill(defDrill));
    }

    /**
     * 修改演练管理
     */
    @Log(title = "演练管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DefDrill defDrill)
    {
        return toAjax(defDrillService.updateDefDrill(defDrill));
    }

    /**
     * 删除演练管理
     */
    @Log(title = "演练管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{drillIds}")
    public AjaxResult remove(@PathVariable Integer[] drillIds)
    {
        return toAjax(defDrillService.deleteDefDrillByDrillIds(drillIds));
    }
}
